<template>
  <div v-if="show" class="modal-overlay" @click="closeModal">
    <div class="modal-content" @click.stop>
      <div class="modal-header">
        <h3>{{ title }}</h3>
        <button class="close-button" @click="closeModal">&times;</button>
      </div>
      <div class="modal-body">
        <p>{{ message }}</p>
      </div>
      <div class="modal-footer">
        <button class="confirm-button" @click="closeModal">确定</button>
      </div>
    </div>
  </div>
</template>

<script setup>
import {ref} from 'vue';

// 接收外部传入的属性
const props = defineProps({
  title: {
    type: String,
    default: '提示',
  },
  message: {
    type: String,
    default: '未找到匹配的商品。',
  },
  show: {
    type: Boolean,
    default: false,
  },
});

// 触发关闭事件
const emit = defineEmits(['close']);
const closeModal = () => emit('close');
</script>

<style scoped>
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(255, 255, 255, 0.9);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.modal-content {
  border-radius: 50px;
  width: 80%;
  max-width: 400px; /* 可选：限制最大宽度 */
  height: 300px;
  background-color: #fff8f8;
  box-shadow: #b1b1b1 3px 3px 3px;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 20px;
  box-sizing: border-box;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h3 {
  margin: 0;
  font-size: 18px;
  font-weight: bold;
  color: blue;
}

.close-button {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: #333;
}

.modal-body {
  font-size: 16px;
  color: #555;
  flex-grow: 1;
  display: flex;
  justify-content: center;
  align-items: center;
}

.modal-footer {
  display: flex;
  justify-content: center;
}

.confirm-button {
  width: 300px;
  border: none;
  height: 100px;
  border-radius: 30px;
  background-color: red;
  color: #ffcccc;
  cursor: pointer;
  transition: background-color 0.3s ease;
}

.confirm-button:hover {
  background-color: darkred;
}
</style>

